package com.fqyd.campustransaction.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fqyd.campustransaction.mapper.OrderMapper;
import com.fqyd.campustransaction.model.Order;
import com.fqyd.campustransaction.model.OrderExample;
import com.fqyd.campustransaction.service.OrderService;

/**
 * 订单
 */
@Service
public class OrderServiceImpl implements OrderService {

	@Resource
	private OrderMapper mapper;

	@Override
	public List<Order> getAll() {
		return mapper.selectByExample(new OrderExample());
	}

	@Override
	public void add(Order order) {
		mapper.insert(order);
	}

	@Override
	public void update(Order order) {
		mapper.updateByPrimaryKey(order);
	}

	@Override
	public void delete(String id) {
		mapper.deleteByPrimaryKey(id);
	}

	@Override
	public Order getById(String id) {
		return mapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Order> getByUserId(String userId) {
		OrderExample example = new OrderExample();
		OrderExample.Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		example.setOrderByClause("id DESC");
		return mapper.selectByExample(example);
	}

	@Override
	public List<Order> getByUserAndOrderId(Order order) {
		return mapper.getByUserAndOrderId(order);
	}

}
